package service.vod.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import service.edu.result.R;
import service.vod.service.VodService;
import java.io.IOException;
import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("/vod")
public class VodController {
    @Autowired
    private VodService vodService;

    @ApiOperation("上传本地视频至阿里云并返回视频id")
    @PostMapping("uploadVideo")
    public R uploadVideo(MultipartFile file) throws IOException {
        String videoSourceId=vodService.uploadVideo(file);
        return R.Ok().data("videoSourceId",videoSourceId);
    }

    @ApiOperation("根据视频id删除阿里云中的视频")
    @DeleteMapping("deleteVideo/{videoSourceId}")
    public R deleteVideoByVideoId(@ApiParam(name = "videoSourceId",value = "阿里云视频id")
                                   @PathVariable("videoSourceId")String videoSourceId){
        vodService.deleteVideoById(videoSourceId);
        return R.Ok();
    }

    @ApiOperation("根据多个视频id删除阿里云中的视频")
    @DeleteMapping("deleteVideoBatch")
    public R deleteVideoBatch(@ApiParam(name = "videoIdList",value = "阿里云视频id列表")
                              @RequestParam("videoIdList")List<String> videoIdList){
        vodService.deleteVideoBatch(videoIdList);
        return R.Ok();
    }
}
